package com.company.myapplication.utils;

import android.os.Environment;
import android.os.StatFs;
/**
 * @auth: njb
 * @date: 2021/7/28 10:54
 * @desc: 手机内存工具类
 */
public class PhoneMemoryUtils {
    /**
     * 检查sd卡是否有足够的空间
     *
     * @return
     */
    public static boolean checkFreeSpace() {
        long minimum = 500; //要求sd卡最少可用空间已M为单位
        long size = minimum * 1024 * 1024;
        if (getSDFreeSpace() > size) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取sd卡的内存大小
     *
     * @return
     */
    public static long getSDFreeSpace() {
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        long blockSize = stat.getBlockSizeLong();
        long availableBlocks = stat.getAvailableBlocksLong();
        return availableBlocks * blockSize;
    }
}
